home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr31 / hades.zip / USERLIST.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  5KB  |  193 lines

  1.  
  2. /***************
  3. **
  4. **  userlist.c
  5. **  last revised: april 10, 1992
  6. **
  7. **  Userlist version 1.00 alpha, Copyright (C)1992 Zabkar
  8. **  DESPERATE password-cracker 1.0 alpha using HADES engine by Remote.
  9. **
  10. **  Userlist creates a dictionary from all usernames from the passwordlist
  11. **  on stdin or the file, specified with the -f switch. Output is written on
  12. **  stdout or the file defined with the -o switch.
  13. **
  14. **  Usage: userlist [-c] [-l] [-1] [-r] [-n] [-f passwordfile] [-o outfile]
  15. **
  16. **  root@waves.hacktic.nl (Zabkar)
  17. **  root@room101.hacktic.nl (Remote)
  18. **
  19. */
  20.  
  21. #include <stdio.h>
  22. #include <string.h>
  23. #include "dictword.h"
  24. #include "pwd.h"
  25.  
  26.  
  27. FILE *outfile;
  28. FILE *infile;
  29.  
  30. extern FILE *_pw_file;     /* So sneaky it could have been from CC! */
  31.  
  32.  
  33. /***************
  34.  haltusage()
  35.  prints correct usage and exits
  36. ****************/
  37.  
  38. void haltusage()
  39. {
  40.   fprintf(stderr,
  41.   "Userlist version 1.00 alpha, Copyright (C)1992 Zabkar\n"\
  42.   "DESPERATE password-cracker 1.0 alpha using HADES engine by Remote.\n\n"\
  43.   "Usage: userlist [-c] [-l] [-1] [-r] [-n] [-f passwordfile] "\
  44.   "[-o outfile]\n\n"\
  45.   "\t-c: capitalize whole word\n"\
  46.   "\t-l: lowercase whole word\n"\
  47.   "\t-1: all lowercase, first uppercase\n"\
  48.   "\t-r: all selected options reversed, too\n"\
  49.   "\t-f: read from 'passwordfile' instead of stdin\n"\
  50.   "\t-o: write to 'outfile' instead of stdout\n\n"\
  51.   "Use of one of the options c, l or 1 causes the normal word to disapear,\n"\
  52.   "to have the normal form back again, add the -n switch.\n\n"\
  53.   "no -f specified: passwordfile read from stdin\n"\
  54.   "no -o specified: output written to stdout\n");
  55.   exit(0);
  56. }
  57.  
  58.  
  59.  
  60. /***************
  61.  createuserlist()
  62.  creates a userlist from input given on file inf and writes output to
  63.  file of. All conversions of mode are taken care of.
  64. ****************/
  65.  
  66. void createuserlist(FILE *inf, FILE *of, int mode)
  67. {
  68.     struct passwd *buf;
  69.     char buffer[256];
  70.     char dest[256];
  71.  
  72.     _pw_file = inf;
  73.  
  74.     while ((buf=getpwent()) != NULL)
  75.     {
  76.        strcpy(buffer, "");
  77.        if (mode & NORMAL || mode & EXTNORMAL)
  78.        {
  79.           strcat(buffer, buf->pw_name);
  80.           strcat(buffer, "\n");
  81.        }
  82.  
  83.        if (mode & LOWER)
  84.        {
  85.           strcat(buffer, all_lower(dest, buf->pw_name));
  86.           strcat(buffer, "\n");
  87.        }
  88.  
  89.        if (mode & UPPER)
  90.        {
  91.           strcat(buffer, all_upper(dest, buf->pw_name));
  92.           strcat(buffer, "\n");
  93.        }
  94.  
  95.        if (mode & FIRSTUP)
  96.        {
  97.           strcat(buffer, first_upper(dest, buf->pw_name));
  98.           strcat(buffer, "\n");
  99.        }
  100.  
  101.        if (mode & REVERSE)
  102.        {
  103.           reverse(dest, buffer);    /* reverse of all the above */
  104.           strcat(buffer, &dest[1]); /* strip leading newline */
  105.           strcat(buffer, "\n");     /* add line-feed to end */
  106.        }
  107.  
  108.        fprintf(of, "%s", buffer);   /* Print all words on of */
  109.     }
  110. }
  111.  
  112.  
  113.  
  114. /***************
  115.  main()
  116.  main function of program mailist
  117. ****************/
  118.  
  119. main(char argc, char **argv)
  120. {
  121.   char fname[80], oname[80];
  122.   int i;
  123.   int convmode = NORMAL;
  124.  
  125.   strcpy(fname, "");
  126.   strcpy(oname, "");
  127.  
  128.   if (argc > 1)
  129.   {
  130.     for (i=1; i<argc; i++)
  131.     {
  132.       switch(argv[i][0])
  133.       {
  134.       case '-': switch(toupper(argv[i][1]))
  135.           {
  136.             case 'F' : if (strlen(argv[i]) > 2)
  137.                  strcpy(fname, &argv[i][2]);
  138.                    else if (argc < (i+2))
  139.                  haltusage();
  140.                    else
  141.                  strcpy(fname, argv[++i]);
  142.                    break;
  143.             case 'O' : if (strlen(argv[i]) > 2)
  144.                  strcpy(oname, &argv[i][2]);
  145.                    else if (argc < (i+2))
  146.                  haltusage();
  147.                    else
  148.                  strcpy(oname, argv[++i]);
  149.                    break;
  150.             case 'C': convmode |= UPPER; convmode &= ~NORMAL; break;
  151.             case 'L': convmode |= LOWER; convmode &= ~NORMAL; break;
  152.             case '1': convmode |= FIRSTUP; convmode &= ~NORMAL; break;
  153.             case 'R': convmode |= REVERSE; break;
  154.             case 'N': convmode |= EXTNORMAL; break;
  155.             default  : haltusage();
  156.           }
  157.           break;
  158.       default : haltusage();
  159.       }
  160.     }
  161.   }
  162.  
  163.   if (strcmp(fname,""))
  164.     infile = fopen(fname, "rt");
  165.   else
  166.     infile = stdin;
  167.  
  168.   if (!infile)
  169.     {
  170.     fprintf(stderr, "%s: couldn't open file\n", fname);
  171.     exit(0);
  172.     }
  173.  
  174.   if (strcmp(oname, ""))
  175.     outfile = fopen(oname, "wt");
  176.   else
  177.     outfile = stdout;
  178.  
  179.   if (!outfile)
  180.     {
  181.     fprintf(stderr, "%s: could't create file\n", oname);
  182.     exit(0);
  183.     }
  184.  
  185.   createuserlist(infile, outfile, convmode);
  186.  
  187.   fclose(infile);
  188.   fclose(outfile);
  189.  
  190.   }
  191.  
  192. /* EOF USERLIST.C */
  193.